A variable is a storage location with an identifier. The value of the variable can change.
DECLARE <identifier> : <data type>
Variables can be expressed in identifier tables, which include:
A constant is a named storage location. The value of the constant can not change.
CONSTANT <identifier> = <value>
Provides a selection of 2 possible pathways
IF <condition> THEN
<statement(s)>
ELSE
<statement(s)>
ENDIF
A condition consists of at least one logic proposition. Logic propositions use comparison & relational operators.
| Operator | Comparison |
|---|---|
| = | Equal to |
| < | Less than |
| > | Greater than |
| <= | Less than or equal to |
| >= | Greater than or equal to |
| <> | Unequal to |
Selection of multiple pathways
Each condition can be:
CASE OF <expression>
<value1>: <statement(s)>
<value2>, <value3>: <statements(s)>
<value4> to <value5>: <statement(s)>
OTHERWISE <statement(s)> //optional; used for error trapping
ENDCASE
Iterates a set number of times
FOR <control variable> ← s TO e STEP i // STEP is optional
<statement(s)>
ENDFOR
Post-conditional (REPEAT...UNTIL) loopA post-conditional loop must run at least once. The condition is evaluated at the end.Aas long as the condition evaluates to false, the loop runs again. The loop will terminate once the condition evaluates to true.
REPEAT
<statement(s)>
UNTIL <condition>
Pre-conditional (WHILE) loopA pre-conditional loop doesn’t always run. This evaluates the condition at the start. The loop will execute the statement as long as the condition evaluates to true, and will terminate once the condition evaluates to false.
WHILE <condition>
<statement(s)>
ENDWHILE
Modular programming: The process of subdividing a computer program into separate sub-programs.
Modules: Seperate software component
Benefits:
A subroutine is a set of instructions that performs a specific task as part of a larger program. Defined away from the program, and called with an identifier when needed. 2 types; procedures & functions.
ProceduresA subroutine that doesn’t return a value
PROCEDURE <identifier> (<parameter1>: <dataType> …)
<statement(s)>
ENDPROCEDURE
CALL <identifier>
May be given data - using variables called parameters passed in as values called arguments
FunctionsA subroutine that returns a value
FUNCTION <identifier> (<parameter1>: <dataType> …) RETURNS dataType
<statement(s)>
ENDFUNCTION
call ← identifier()
Example functions: